package org.jsola.hr.helper;

import org.jsola.hr.dto.EmpSocMonthAddDTO;
import org.jsola.hr.dto.EmpSocMonthUpdateDTO;
import org.jsola.hr.entity.EmpSocMonthDO;
import org.jsola.hr.query.EmpSocMonthQuery;
import org.jsola.hr.service.IEmpSocMonthService;
import org.jsola.hr.vo.EmpSocMonthVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工参保信息月统计
 *
 * @author zhr
 */
@Component
public class EmpSocMonthTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpSocMonthService empSocMonthService;

    /**
     * 生成add测试数据
     * @return EmpSocMonthAddDTO
     */
    public EmpSocMonthAddDTO getEmpSocMonthAddDTO(){
        EmpSocMonthAddDTO empSocMonthAddDTO = new EmpSocMonthAddDTO();
        empSocMonthAddDTO.setYear(getRandomValue("varchar",32));
        empSocMonthAddDTO.setMonth(getRandomValue("varchar",32));
        empSocMonthAddDTO.setCompanyId(getRandomValue("varchar",32));
        return empSocMonthAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpSocMonthUpdateDTO
     */
    public EmpSocMonthUpdateDTO getEmpSocMonthUpdateDTO(EmpSocMonthVO empSocMonthVO){
        return empSocMonthService.selectDOById(empSocMonthVO.getId(), SITE_ID).to(EmpSocMonthUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpSocMonthQuery
     */
    public EmpSocMonthQuery getEmpSocMonthQuery() {
        EmpSocMonthQuery empSocMonthQuery = new EmpSocMonthQuery();
        List<EmpSocMonthDO> empSocMonthDOList = empSocMonthService.list(new EmpSocMonthDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empSocMonthDOList)) {
            EmpSocMonthDO empSocMonthDO = empSocMonthDOList.get(0);
            empSocMonthQuery = empSocMonthDO.to(EmpSocMonthQuery.class);
        }
        return empSocMonthQuery;
    }

    /**
     * 保存示例
     * @return EmpSocMonthVO
     */
    public EmpSocMonthVO saveEmpSocMonthExample(){
        EmpSocMonthAddDTO addDTO = this.getEmpSocMonthAddDTO();
        EmpSocMonthVO empSocMonthVO = empSocMonthService.save(addDTO,buildTokenUser());
        return empSocMonthVO;
    }


}

